<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>资方核销明细</title>
	<jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div class="searchArea">
		<form id="searchBar">
			<div class="fieldset1 clearFix">
				<div class="FXBR">
					<div class="fieldBox">
						<div class="label">合同号</div>
						<div class="field">
							<input name="crCntNo" id="crCntNo" type="text" class="ui-textbox" value="" ligerui="width: 160">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">资金方</div>
						<div class="field">
							<select name="loanChannel" id="loanChannel">
								<option value="">--资金方--</option>
								<option value="WKXT">五矿信托</option>
								<option value="YNXT">云南信托</option>
							</select>
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">推送类型</div>
						<div class="field">
							<select name="pushType" id="pushType">
								<option value="">--全部--</option>
								<option value="1">自动</option>
								<option value="2">手动</option>
							</select>
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">推送状态</div>
						<div class="field">
							<select name="state" id="state">
								<option value="">--全部--</option>
								<option value="1">推送中</option>
								<option value="2">核销成功</option>
								<option value="3">核销失败</option>
							</select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">核销时间</div>
						<div class="field">
							<input name="payDt" id="payDt" type="text" class="ui-datepicker" ligerui="width: 115" readonly="readonly">
						</div>
					</div>
				</div>

				<div class="clearFix"></div>
				<div class="btnsBox formBtns notRight">
					<span id="searchBtn" onclick="searchBtn();" class="sq-button-round">查询</span>
					<span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
					<span id="addBtn" onclick="execPushData();" class="sq-button-round">手动推送</span>
					<span id="synVerifyStateWK" onclick="synVerifyStateWK();" class="sq-button-round">五矿核销结果同步</span>
					<span id="synVerifyStateYN" onclick="synVerifyStateYN();" class="sq-button-round">云信核销结果同步</span>
					<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
				</div>
			</div>
		</form>
	</div>
</div>
<div id="mcrBillVerifyGrid" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	$(function () {
		initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		//initEvent();
	});

	function initEvent(){
		$("#redisBtn").click(function(event) {
			var url = '<%=path%>/mcr/mcrBillVerify/getRedisInfo.do';
			AjaxUtils.ajaxGet(url, {}, redisCallback);
		});
	}

	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}

	//查询按钮事件
	function searchBtn(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		for (name in data){
			grid.setParm(name,data[name]);
		};
		grid.reload();
	}

	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}

	//初始化列表
	function initGrid(){
		$("#mcrBillVerifyGrid").ligerGrid({
			url: '<%=path%>/mcr/mcrBillVerify/initList.do',
			method : 'post',
			isSingleCheck: false,
			parms:getSearchParams(),
			columns: [
				{display: '序号', name: 'id', width: 200, align: 'left', enabledSort: false, hide: true},
				{ display: '推送时间', name: 'crtTm', width: 120, enabledSort:true ,render:renderDate},
				{ display: '资金方', name: 'loanChannel', width: 150, enabledSort:true,
					render:function(rowData){
						if(rowData.loanChannel=="WKXT"){
							return "五矿信托";
						}else if(rowData.loanChannel=="YNXT"){
							return "云南信托";
						}
					}},
				{ display: '合同号', name: 'crCntNo', width: 150, enabledSort:true},
				{ display: '总期次', name: 'allPayPd', width: 150, enabledSort:true},
				{ display: '期次', name: 'payPd', width: 150, enabledSort:true},
				{ display: '数据类型', name: 'busType', width: 150, enabledSort:true,
					render:function(rowData){
						if(rowData.busType=="1"){
							return "正常还款";
						}else if(rowData.busType=="2"){
							return "提前结清";
						}else{
							return "逾期";
						}
					}
				},
				{ display: '应还本金', name: 'capAmt', width: 150, enabledSort:true},
				{ display: '应还利息', name: 'intrAmt', width: 150, enabledSort:true},
				{ display: '应还罚息', name: 'ovdAmt', width: 150, enabledSort:true},
				{ display: '实还本金', name: 'paidCapAmt', width: 150, enabledSort:true},
				{ display: '实还利息', name: 'paidIntrAmt', width: 150, enabledSort:true},
				{ display: '实还罚息', name: 'paidOvdAmt', width: 150, enabledSort:true},
				{ display: '实还时间', name: 'payDt', width: 150, enabledSort:true,render:renderDate},
				{ display: '推送类型', name: 'pushType', width: 150, enabledSort:true,
					render:function(rowData){
						if(rowData.pushType=="1"){
							return "自动";
						}else{
							return "手动";
						}
					}
				},
				{ display: '推送结果', name: 'state', width: 150, enabledSort:true,
					render:function(rowData){
						if(rowData.state=="1"){
							return "核销中";
						}else if(rowData.state=="2"){
							return "核销成功";
						}else{
							return "核销失败";
						}
					}
				},
				{ display: '失败原因', name: 'remark', width: 150, enabledSort:true}
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton : true,
			width: '100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,
			rownumbers:true

		});
		grid = liger.get("mcrBillVerifyGrid");
		grid.setHeight(100);
	}
	//手动执行回调
	function verifyCallback(msg){
		if(msg.success == 1){
			UIUtils.alertSuccess(msg.info);
		}else{
			UIUtils.alertError(msg.info);
		}
	}

	//手动推送记录
	function execPushData(){
		$.ligerDialog.confirm('确定执行该操作吗?', function (flag) {
			if(flag == false)return;
			var selectedRows = grid.getSelectedRows();
			if(selectedRows.length == 0){
				UIUtils.alertError("请选择数据!");
				return;
			}
			var pkIds = new Array();
			for(var i=0;i<selectedRows.length;i++){
				var pkId = selectedRows[i].id;
				if ('3' != selectedRows[i].state){
					//核销失败记录才可以手工核销
					UIUtils.alertError("手工核销只能核销失败的记录！");
					return ;
				}
				pkIds[i] = pkId;
			}
			console.info("ids===="+JSON.stringify(pkIds));
			var url = '<%=path%>/mcr/mcrBillVerify/execVerifyForBill.do';
			AjaxUtils.ajaxPost(url, {billVerifyIds:pkIds},null,false);
			UIUtils.alertSuccess("手动核销执行成功！");
		});
		<%--var _id = selectedRows[0].id;--%>
		<%--Add_navTab('Comp_2','修改','<%=path%>/mcr/mcrBillVerify/toAddPage.do?id='+_id);--%>
	}

	//redis回调
	function redisCallback(msg){
		if(msg.success == 1){
			UIUtils.alertSuccess(msg.data);
		}else{
			UIUtils.alertError(msg.info);
		}
	}

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

	//清空按钮事件
	function clearBtn(){
		$("#resetBtn").click();  //重置 input-text
		var form = new liger.get("searchBar");
		form.setData({  //重置select等特殊表单
			"pushType":"",
			"loanChannel":"",
			"state":""
		});
	}

	function iframeResize () {
		if (parent.mainApp) {
			parent.mainApp.parentTab.onResize();
		};
	}


	//同步核销状态 五矿
	function synVerifyStateWK(){
		$.ligerDialog.confirm('确定执行该操作吗?', function (flag) {
			if(flag == false)return;
			var url = '<%=path%>/mcr/mcrBillVerify/verifySynState.do';
			AjaxUtils.ajaxPost(url, {loanChannel:"WKXT"}, null,false);
			UIUtils.alertSuccess("状态同步执行成功！");
		});
	}
	//同步核销状态 云信
	function synVerifyStateYN(){
		$.ligerDialog.confirm('确定执行该操作吗?', function (flag) {
			if(flag == false)return;
			var url = '<%=path%>/mcr/mcrBillVerify/verifySynState.do';
			AjaxUtils.ajaxPost(url, {loanChannel:"YNXT"}, null,false);
			UIUtils.alertSuccess("状态同步执行成功！");
		});
	}
</script>

</body>
</html>